#include<bits/stdc++.h>
using namespace std;
long long t,n,m,l,V,d[10000005],v[10000005],a[100000005],p[10000005],ans1,ans2,num;
int main()
{
     freopen("detect.in","r",stdin);
     freopen("detect.out","w",stdout);
     ios::sync_with_stdio(0);
     cin.tie(0);
     cout.tie(0);
     cin>>t;
     for(int i=1;i<=t;i++)
     {
         cin>>n>>m>>l>>V;
         for(int j=1;j<=n;j++)
         {
             cin>>d[j]>>v[j]>>a[j];
         }
         for(int j=1;j<=m;j++)
         {
             cin>>p[j];
         }
         for(int j=1;j<=n;j++)
         {
             for(int k=1;k<=m;k++)
             {
                 if(p[k]>d[j])
                 {
                     if(v[j]>V)
                     {
                         ans1++;
                         break;
                     }
                 }
             }
         }
         if(ans1!=0)
         {
         ans2=m-1;
         }
         else
         {
             ans2=m;
         }
         cout<<ans1<<" "<<ans2<<endl;
     }
     return 0;
}
